﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>订单投料完成率看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .header-title {
      font-size: 24px !important;
    }

    .el-form-item__label {
      color: #fff;
    }

    .el-form-item {
      margin-bottom: 0px;
    }

    .chart-title {
      text-align: center;
      color: #fff;
      padding-top: 5px;
      font-size: 18px;
    }

    .chart {
      width: 100%;
      font-size: 40px;
      font-weight: bold;
      cursor: pointer;
      text-align: center;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <el-row>
        <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
        <el-col :span="12" class="header-title">订单投料完成率看板</el-col>
        <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
      </el-row>

      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="订单计划投料日期:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>

      <el-row>
        <el-col :span="24" style="position:relative;">
          <div class="tooltip">
            统计说明
            <el-popover placement="top-start" title="统计说明:" width="600" trigger="hover">
              <i class="el-icon-info" slot="reference"></i>
              <p>【未到料】: 非自投料，且当前处于【到料确认】状态的批次。</p>
              <p>【已到料】: 不满足【未到料】状态的批次。</p>
          </div>
          <dv-border-box-10 style="margin-top:10px;">
            <div class="chart-title">订单投料完成率</div>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="rateChart"></div>
          </dv-border-box-10>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24" style="position:relative;">
          <div class="tooltip">
            统计说明
            <el-popover placement="top-start" title="统计说明:" width="600" trigger="hover">
              <i class="el-icon-info" slot="reference"></i>
              <p>【未到料】: 非自投料，且当前处于【到料确认】状态的批次。</p>
              <p>【已到料】: 不满足【未到料】状态的批次。</p>
          </div>
          <dv-border-box-10 style="margin-top:10px;">
            <div class="chart-title">订单投料完成情况</div>
            <div class="chart" :style="{ height: chartHeight +'px' }" id="chart"></div>
          </dv-border-box-10>
        </el-col>
      </el-row>

      <!-- 柱状图明细 -->
      <el-dialog :title="chartDetail.title" :width="'98%'" :top="'10px'" :visible.sync="chartDetail.dialogVisiable"
        center="true">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="chartDetail.dataList" stripe border>
          <el-table-column type="index" width="40"></el-table-column>
          <el-table-column label="操作" width="240">
            <template slot-scope="scope">
              <el-button type="success" icon="el-icon-view" size="mini" @click="showContainerDetail(scope.row)">
                查看批次
              </el-button>
              <el-button type="primary" icon="el-icon-download" size="mini" @click="exportDetail">
                导出
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="分厂" prop="factoryname" width="150" show-overflow-tooltip></el-table-column>
          <el-table-column label="订单号" prop="mfgordername" show-overflow-tooltip></el-table-column>
          <el-table-column label="订单数量" prop="mfgqty" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="件号" prop="productname" show-overflow-tooltip></el-table-column>
          <el-table-column label="计划到料时间" prop="plandate" width="120" :formatter="splitDate"></el-table-column>
          <el-table-column label="实际到料时间" prop="materialdate" width="120" :formatter="splitDate"></el-table-column>
          <el-table-column label="到料数" prop="daoliaoqty" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="缺料数" prop="queliaoqty" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="状态" prop="status" width="120" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status === '已到料'" type="success">{{scope.row.status}}</el-tag>
              <el-tag v-else type="danger">{{scope.row.status}}</el-tag>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleChartDetailCurrentChange"
          :current-page="chartDetail.queryInfo.currentPage" :page-sizes="[12]"
          :page-size="chartDetail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
          :total="chartDetail.total">
        </el-pagination>
      </el-dialog>

      <!-- 批次明细 -->
      <el-dialog :title="containerDetail.title" :width="'98%'" :top="'10px'"
        :visible.sync="containerDetail.dialogVisiable" center="true">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="containerDetail.dataList" stripe border>
          <el-table-column type="index" width="40"></el-table-column>
          <el-table-column label="分厂" prop="factoryname" width="150" show-overflow-tooltip></el-table-column>
          <el-table-column label="订单号" prop="mfgordername" show-overflow-tooltip></el-table-column>
          <el-table-column label="订单数量" prop="mfgqty" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="件号" prop="productname" show-overflow-tooltip></el-table-column>
          <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip></el-table-column>
          <el-table-column label="在制数" prop="qty" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="报废数" prop="scrapqty" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="发料数" prop="faliaoqty" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="计划到料时间" prop="plandate" width="120" :formatter="splitDate"></el-table-column>
          <el-table-column label="实际到料时间" prop="materialdate" width="120" :formatter="splitDate"></el-table-column>
          <el-table-column label="当前序" prop="workflowstepname" show-overflow-tooltip></el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleContainerDetailCurrentChange"
          :current-page="containerDetail.queryInfo.currentPage" :page-sizes="[12]"
          :page-size="containerDetail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
          :total="containerDetail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        currentTime: '',
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: { selectdate: '' },
        chartDetail: {
          dialogVisiable: false,
          queryInfo: {
            factoryname: '',
            seriesName: '',
            currentPage: 1,//当前页
            pageSize: 12//每页显示条数
          },
          title: '',
          dataList: [],
          total: 0
        },
        containerDetail: {
          dialogVisiable: false,
          queryInfo: {
            mfgordername: '',
            currentPage: 1,//当前页
            pageSize: 12//每页显示条数
          },
          title: '',
          dataList: [],
          total: 0
        },
        rules: {
          selectdate: [{ required: true, message: '订单计划投料日期不能为空', trigger: 'change' }]
        },
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff', color: '#66b1ff' },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] },
        chartHeight: (window.innerHeight - 200) / 2
      },
      methods: {
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              echarts.dispose(document.getElementById("rateChart"));
              echarts.dispose(document.getElementById("chart"));
              let rateChart = echarts.init(document.getElementById('rateChart'));
              let chart = echarts.init(document.getElementById('chart'));
              rateChart.showLoading(this.loadingConfig);
              chart.showLoading(this.loadingConfig);

              const { data: { data, meta, total } } = await axios.post('../handler/board/MfgorderTouLiaoInfoDashBoard.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              rateChart.hideLoading();
              chart.hideLoading();

              if (meta.status === 500) { return this.$message.error(meta.msg); }
              if (data.length === 0) { return; }

              echarts.dispose(document.getElementById("rateChart"));
              echarts.dispose(document.getElementById("chart"));
              rateChart = echarts.init(document.getElementById('rateChart'));
              chart = echarts.init(document.getElementById('chart'));

              let arrFactoryname = []; //分厂
              let arrYDLRate = []; //已到料订单完成率
              let arrWDLRate = []; //未到料订单完成率
              let arrTotal = []; //总数
              let arrYDL = []; //已到料
              let arrWDL = [];// 未到料

              for (const i of data) {
                arrFactoryname.push(i.factoryname);
                arrTotal.push(i.total); //总数
                arrYDL.push(i.ydl); // 已到料
                arrWDL.push(i.wdl); // 未到料
                arrYDLRate.push(i.ydlrate); // 已到料订单完成率
                arrWDLRate.push(i.wdlrate)// 未到料订单完成率
              }

              let rateOption = barOption({ isLableFormat: false, provideNumber: 6 });
              rateOption.legend.data = ['已到料率', '未到料率'];
              rateOption.xAxis.data = arrFactoryname;
              rateOption.yAxis[0].axisLabel.formatter = function (data) { return data + "%"; };
              rateOption.yAxis[1].show = false;

              rateOption.series[0] = _.merge(rateOption.series[0], {
                name: '已到料率',
                data: arrYDLRate,
                label: { color: colorList.green.color, formatter: '{c}%' },
                itemStyle: { color: { colorStops: colorList.green.colorStops } }
              });

              rateOption.series[1] = _.merge(_.cloneDeep(rateOption.series[0]), {
                name: '未到料率',
                data: arrWDLRate,
                label: { color: colorList.red.color },
                itemStyle: { color: { colorStops: colorList.red.colorStops } }
              });

              let chartOption = barOption({ isLableFormat: false, provideNumber: 6 });
              chartOption.legend.data = ['订单总数', '已到料', '未到料'];//设置图例文字
              chartOption.xAxis.data = arrFactoryname;//x轴数据
              chartOption.yAxis[1].show = false;

              chartOption.series[0] = _.merge(chartOption.series[0], {
                name: '订单总数',
                data: arrTotal,
                label: { color: colorList.blue.color },
                itemStyle: { color: { colorStops: colorList.blue.colorStops } }
              });

              chartOption.series[1] = _.merge(_.cloneDeep(chartOption.series[0]), {
                name: '已到料',
                data: arrYDL,
                label: { color: colorList.green.color },
                itemStyle: { color: { colorStops: colorList.green.colorStops } }
              });

              chartOption.series[2] = _.merge(_.cloneDeep(chartOption.series[0]), {
                name: '未到料',
                data: arrWDL,
                label: { color: colorList.red.color },
                itemStyle: { color: { colorStops: colorList.red.colorStops } }
              });

              rateChart.setOption(rateOption);
              chart.setOption(chartOption);

              window.addEventListener('resize', () => {
                rateChart.resize();
                chart.resize();
              });

              chart.on('click', (params) => {
                if (params.value == 0) { return; }
                this.chartDetail.queryInfo.currentPage = 1;
                this.chartDetail.queryInfo.factoryname = params.name;
                this.chartDetail.queryInfo.seriesName = params.seriesName;
                this.chartDetail.title = `【${params.name}】【${params.seriesName}】`;
                this.chartDetail.dialogVisiable = true;
                this.getDetail();
              })
            }
          })
        },
        // 柱状图明细
        async getDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/MfgorderTouLiaoInfoDashBoard.ashx?action=getChartDetail', {
            type: 'getChartDetail',
            ...this.queryInfo,
            ...this.chartDetail.queryInfo
          });
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.chartDetail.dataList = data;
          this.chartDetail.total = total;
        },
        showContainerDetail(row) {
          this.containerDetail.queryInfo.currentPage = 1;
          this.containerDetail.queryInfo.mfgordername = row.mfgordername;
          this.containerDetail.title = `【${row.mfgordername}】流水卡到料情况明细`;
          this.containerDetail.dialogVisiable = true;
          this.getContainerDetail();
        },
        // 订单批次明细
        async getContainerDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/MfgorderTouLiaoInfoDashBoard.ashx?action=getContainerDetail', {
            type: 'getContainerDetail',
            ...this.queryInfo,
            ...this.containerDetail.queryInfo
          });
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.containerDetail.dataList = data;
          this.containerDetail.total = total;
        },
        handleChartDetailCurrentChange(newPage) {
          this.chartDetail.queryInfo.currentPage = newPage;
          this.getDetail();
        },
        handleContainerDetailCurrentChange(newPage) {
          this.containerDetail.queryInfo.currentPage = newPage;
          this.getContainerDetail();
        },
        exportDetail() {
          const config = {
            url: '../handler/board/MfgorderTouLiaoInfoDashBoard.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo, ...this.chartDetail.queryInfo }
          }
          exportExcelData(config, this);
        }
      },
      mounted() {
        this.chartHeight = (window.innerHeight - 110 - this.chartRow * 40) / this.chartRow
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        window.addEventListener('resize', () => {
          this.chartHeight = (window.innerHeight - 200) / 2;
        });
        setTimeout(incrementNumber, 500);
        const startOfMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [startOfMonth, endOfMonth];
        this.getData();
      }
    })
  </script>
</body>

</html>